View Javadoc

1   // Interface.java, created Thu Sep  5 10:48:53 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.ClassLib.apple13_osx;
5   
6   import java.util.Collections;
7   import joeq.Class.PrimordialClassLoader;
8   import joeq.Class.jq_Class;
9   import joeq.ClassLib.ClassLibInterface;
10  import joeq.Runtime.ObjectTraverser;
11  import joeq.Runtime.SystemInterface;
12  import joeq.UTF.Utf8;
13  import jwutil.collections.AppendIterator;
14  
15  /***
16   * Interface
17   *
18   * @author  John Whaley <jwhaley@alum.mit.edu>
19   * @version $Id: Interface.java 1941 2004-09-30 03:37:06Z joewhaley $
20   */
21  public final class Interface extends joeq.ClassLib.Common.InterfaceImpl {
22  
23      /*** Creates new Interface */
24      public Interface() {}
25  
26      public java.util.Iterator getImplementationClassDescs(joeq.UTF.Utf8 desc) {
27          if (ClassLibInterface.USE_JOEQ_CLASSLIB && desc.toString().startsWith("Ljava/")) {
28              joeq.UTF.Utf8 u = joeq.UTF.Utf8.get("Ljoeq/ClassLib/apple13_osx/"+desc.toString().substring(1));
29              return new AppendIterator(super.getImplementationClassDescs(desc),
30                                        Collections.singleton(u).iterator());
31          }
32          return super.getImplementationClassDescs(desc);
33      }
34  
35      public ObjectTraverser getObjectTraverser() {
36          return apple13_osxObjectTraverser.INSTANCE;
37      }
38      
39      public static class apple13_osxObjectTraverser extends CommonObjectTraverser {
40          public static apple13_osxObjectTraverser INSTANCE = new apple13_osxObjectTraverser();
41          protected apple13_osxObjectTraverser() {}
42          public java.lang.Object mapInstanceField(java.lang.Object o, joeq.Class.jq_InstanceField f) {
43              if (IGNORE_THREAD_LOCALS) {
44                  jq_Class c = f.getDeclaringClass();
45                  if (c == PrimordialClassLoader.getJavaLangThread()) {
46                      String fieldName = f.getName().toString();
47                      if (fieldName.equals("threadLocals") || fieldName.equals("inheritableThreadLocals")) {
48                          // 1.3.1_05 and greater uses the 1.4 implementation of thread locals.
49                          // see Sun BugParade id#4667411.
50                          // we check the type of the field and return the appropriate object.
51                          if (f.getType().getDesc() == Utf8.get("Ljava/util/Map;")) {
52                              return java.util.Collections.EMPTY_MAP;
53                          } else if (f.getType().getDesc() == Utf8.get("Ljava/lang/ThreadLocal$ThreadLocalMap;")) {
54                              return null;
55                          } else {
56                              SystemInterface.debugwriteln("Unknown type for field "+f);
57                              return null;
58                          }
59                      }
60                  }
61              }
62              return super.mapInstanceField(o, f);
63          }
64      }
65      
66  }